package com.wntms.wgj.dao;

import com.wntms.wgj.pojo.CustomerInformations;
import com.wntms.wgj.pojo.CustomerIns;
import com.wntms.wgj.pojo.FreightContracts;
import com.wntms.wgj.pojo.FreightSettles;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FreightSettleDao {
    /**
     * 查询所有货运单信息
     * @return
     */
    @Select("select * from freight_settle")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "fid",column = "fid"),
            @Result(property = "cid",column = "cid"),
            @Result(property = "ciid",column = "ciid"),
            @Result(property = "moneyed",column = "moneyed"),
            @Result(property = "isSettle",column = "issettle"),
            @Result(property = "freightContracts",column = "fid",javaType = FreightContracts.class,
                    one = @One(select = "com.wntms.wgj.dao.FreightContractDaos.findById")),
            @Result(property = "customerInformations",column = "cid",javaType = CustomerInformations.class,
                    one = @One(select = "com.wntms.wgj.dao.CustomerInformationDaos.findById")),
            @Result(property = "customerIns",column = "ciid",javaType = CustomerIns.class,
                    one = @One(select = "com.wntms.wgj.dao.CustomerInDaos.findById"))
    })
    public List<FreightSettles> findFreightSettles();

    /**
     * 货运单结算
     * @param freightSettles
     * @return
     */
    @Update("update freight_settle set issettle = #{isSettle},moneyed = #{moneyed} where id = #{id}")
    public int updateSettle(FreightSettles freightSettles);

    /**
     * 删除记录
     * @param id
     * @return
     */
    @Delete("delete from freight_settle where id = #{id}")
    public int deleteSettle(Integer id);


    /**
     * 根据货运编号查找
     * @param fid
     * @return
     */
    @Select("select * from freight_settle where fid = #{fid}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "fid",column = "fid"),
            @Result(property = "cid",column = "cid"),
            @Result(property = "ciid",column = "ciid"),
            @Result(property = "moneyed",column = "moneyed"),
            @Result(property = "isSettle",column = "issettle"),
            @Result(property = "freightContracts",column = "fid",javaType = FreightContracts.class,
                    one = @One(select = "com.wntms.wgj.dao.FreightContractDaos.findById")),
            @Result(property = "customerInformations",column = "cid",javaType = CustomerInformations.class,
                    one = @One(select = "com.wntms.wgj.dao.CustomerInformationDaos.findById")),
            @Result(property = "customerIns",column = "ciid",javaType = CustomerIns.class,
                    one = @One(select = "com.wntms.wgj.dao.CustomerInDaos.findById"))
    })
    public FreightSettles findByFid(String fid);
}
